<template>
  <div v-show="showDialog" id="answer-teacher">
    <div class="title-bar">
      <span class="text">答题器</span>
      <span @click="closeDialog()" class="close">X</span>
    </div>
    <div class="title-body">
      <div id="answer-tea"></div>
    </div>
  </div>
</template>

<script>
let eventEmitter = BJY.eventEmitter

export default {
  components: {},
  data () {
    return {
      answer: null,
      showDialog: false
    }
  },
  computed: {},
  watch: {},
  methods: {
    closeDialog () {
      this.showDialog = false
    }
  },
  created () {
    let that = this
    eventEmitter
      .on(
        'ZWZ_ANSWER.yxp',
        (e, data) => {
          that.showDialog = true
          if(!that.answer){
            that.answer = BJY.AnswerTeacher.init({
              element: $('#answer-tea')[0],
              onClose: function () {
                that.showDialog = false
              }
            });
          }
        }
      )
  },
  mounted () {
  },
  beforeDestroy () {
    this.answer && this.answer.destroy && this.answer.destroy()
  }
}
</script>

<style lang="less" scoped>
//@import url(); 引入公共css类
  .title-body{
    margin-top: 0px;
    height: 100%;
  }
  
  #answer-teacher {
    position: absolute;
    z-index: 9999;
    width: 400px;
    height: auto;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  }

  .title-bar {
    position: absolute;
    top: 0;
    height: 30px;
    width: 100%;
    background: #444c63;
    display: flex;
    padding: 0 10px;
    justify-content: space-between;
    align-items: center;
    color: #fff;

    .close {
      cursor: pointer;
    }
  }
</style>
